home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / clsbolt3d.cls < prev    next >
Encoding:
Visual Basic class definition  |  2007-02-26  |  42.8 KB  |  1,440 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Detail"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. '/******************************************************************/
  15. '/*                                                                */
  16. '/*                      TurboCAD for Windows                      */
  17. '/*                   Copyright (c) 1993 - 2001                    */
  18. '/*             International Microcomputer Software, Inc.         */
  19. '/*                            (IMSI)                              */
  20. '/*                      All rights reserved.                      */
  21. '/*                                                                */
  22. '/******************************************************************/
  23.  
  24. Option Explicit
  25.  
  26. 'DBAPI constants
  27. Const gkGraphic = 11
  28. Const gkArc = 2
  29. Const gkText = 6
  30. Const gfCosmetic = 128&
  31.                                                                                                                                                                                              
  32. 'Useful math constants
  33. Const Pi# = 3.14159265
  34. Const Eps = 0.0001
  35. 'Real variant types!
  36. Const typeEmpty = 0
  37. Const typeInteger = 2
  38. Const typeLong = 3
  39. Const typeSingle = 4
  40. Const typeDouble = 5
  41. Const typeCurrency = 6
  42. Const typeDate = 7
  43. Const typeString = 8
  44. Const typeObject = 9
  45. Const typeBoolean = 11
  46. Const typeVariant = 12
  47. Const typeIntegerEnum = typeInteger + 100
  48. Const typeLongEnum = typeLong + 100
  49. Const typeStringEnum = typeString + 100
  50.  
  51. 'Stock property pages
  52. Const ppStockPen = 1
  53. Const ppStockBrush = 2
  54. Const ppStockText = 4
  55. Const ppStockInsert = 8
  56. Const ppStockViewport = 16
  57. Const ppStockAuto = 32
  58.  
  59. 'Property Ids
  60. Const idDiameter = 1
  61. Const idLength = 2
  62. Const idBType = 3
  63. Const idLengthThread = 4
  64.  
  65. Const idDiameterOld = 5
  66. Const idLengthOld = 6
  67. Const idBTypeOld = 7
  68. Const idLengthThreadOld = 8
  69.  
  70. Const idSolid = 9
  71. Const idSolidOld = 10
  72.  
  73.  
  74. 'Property enums
  75. Const NUM_TYPES = 0
  76.  
  77. 'Number of properties, pages, wizards
  78. Const NUM_PROPERTIES = 10
  79. Const NUM_PAGES = 1
  80. Const NUM_WIZARDS = 0
  81.  
  82. Private PColor As Long
  83. Private BColor As Long
  84.  
  85.  
  86. Private Sub Class_Initialize()
  87.     'Initialize class variables
  88. End Sub
  89.  
  90. 'Returns the user-visible description of this RegenMethod
  91. Public Property Get Description() As String
  92.     Description = "SDK Bolt_Screw3D"
  93. End Property
  94.  
  95. 'Returns the persistent class id for this RegenMethod's property section
  96. Public Property Get ClassID() As String
  97.     ClassID = "{FDB6F1C3-9631-11d1-A40A-0000B465872B}"
  98. End Property
  99.  
  100. 'Retrieve types and names
  101. Public Function GetPropertyInfo(Names As Variant, Types As Variant, _
  102.     IDs As Variant, Defaults As Variant) As Long
  103.     ReDim Names(NUM_PROPERTIES), Types(NUM_PROPERTIES), _
  104.         IDs(NUM_PROPERTIES), Defaults(NUM_PROPERTIES)
  105.         
  106.     Names(0) = "Diameter"
  107.     Types(0) = typeDouble
  108.     IDs(0) = idDiameter
  109.     Defaults(0) = 1#
  110.  
  111.     Names(1) = "Length"
  112.     Types(1) = typeDouble
  113.     IDs(1) = idLength
  114.     Defaults(1) = 3#
  115.     
  116.     Names(2) = "BType"
  117.     Types(2) = typeString
  118.     IDs(2) = idBType
  119.     Defaults(2) = "HexBolt"
  120.    
  121.     Names(3) = "LengthThread"
  122.     Types(3) = typeDouble
  123.     IDs(3) = idLengthThread
  124.     Defaults(3) = 1.5
  125.    
  126.     Names(4) = "DiameterOld"
  127.     Types(4) = typeDouble
  128.     IDs(4) = idDiameterOld
  129.     Defaults(4) = 1.5
  130.  
  131.     Names(5) = "LengthOld"
  132.     Types(5) = typeDouble
  133.     IDs(5) = idLengthOld
  134.     Defaults(5) = 3#
  135.     
  136.     Names(6) = "BTypeOld"
  137.     Types(6) = typeString
  138.     IDs(6) = idBTypeOld
  139.     Defaults(6) = "HexBolt"
  140.    
  141.     Names(7) = "LengthThreadOld"
  142.     Types(7) = typeDouble
  143.     IDs(7) = idLengthThreadOld
  144.     Defaults(7) = 1.5
  145.     
  146.     Names(8) = "BoltSolid"
  147.     Types(8) = typeInteger
  148.     IDs(8) = idSolid
  149.     Defaults(8) = 1
  150.     
  151.     Names(9) = "BoltSolidOld"
  152.     Types(9) = typeInteger
  153.     IDs(9) = idSolidOld
  154.     Defaults(9) = 1
  155.    
  156.    GetPropertyInfo = NUM_PROPERTIES
  157. End Function
  158.  
  159. 'Get the number of property pages supporting this RegenMethod
  160. Public Function GetPageInfo(ByVal AGraphic As Object, StockPages As Long, _
  161.     Names As Variant) As Long
  162.     ReDim Names(NUM_PAGES)
  163.  
  164.     'Need the form
  165. '    Load frmBolt3D
  166. '    Names(0) = frmBolt3D.Caption
  167. '    Unload frmBolt3D
  168. ' load from resources
  169.     Names(0) = LoadResString(101)
  170.     StockPages = ppStockBrush + ppStockPen + ppStockAuto
  171.     GetPageInfo = NUM_PAGES
  172. End Function
  173.  
  174. Public Function GetWizardInfo(Names As Variant) As Long
  175.     ReDim Names(NUM_WIZARDS)
  176.     GetWizardInfo = NUM_WIZARDS
  177. End Function
  178.  
  179. 'Enumerate the names and values of a specified property
  180. Public Function GetEnumNames(ByVal PropID As Long, Names As Variant, Values As Variant) As Long
  181.         GetEnumNames = 0
  182. End Function
  183.  
  184. Public Function PageControls(ByVal ThisRegenMethod As Object, ByVal Graphic As Object, ByVal PageNumber As Long, ByVal SaveProperties As Boolean) As Boolean
  185.         'Set up error function
  186.         On Error GoTo Failed
  187.         Dim Diameter#, Length#, LengthThread#
  188.         Dim SSolid%
  189.         If SaveProperties Then
  190.             'OK button on property page was clicked
  191.             'Form is still loaded
  192.             With frmBolt3D
  193.                 'Need On Error statement for the case where you have
  194.                 'RRect Turbo Shape and ahother "shape" selected
  195.                 On Error Resume Next
  196.                 'When the property page is closed, transfer the numeric
  197.                 'Diameter value from the TextBox to the Graphic
  198.                 'Get the value as a double-precision number
  199.                 Diameter# = CDbl(.txtdd.Text)
  200.                 Length# = CDbl(.txtLen.Text)
  201.                 LengthThread# = CDbl(.txtThread.Text)
  202.                 TypeB = .List1.Text
  203.                  If .Surf_Solid.Value = True Then ' if surface
  204.                     SSolid = 0
  205.                  ElseIf .Surf_Solid1.Value = True Then
  206.                     SSolid = 1
  207.                  End If
  208.                 
  209.                 'Make sure it's between 0 and 100
  210.                 If Diameter# < 0# Then Diameter# = 1#
  211.                 If LengthThread > Length Then LengthThread = Length
  212.                 'Set the roundness property value in the Graphic
  213.                 Graphic.Properties("Diameter") = Diameter#
  214.                 Graphic.Properties("Length") = Length#
  215.                 Graphic.Properties("LengthThread") = LengthThread#
  216.                 Graphic.Properties("BType") = TypeB
  217.                 Graphic.Properties("BoltSolid") = SSolid
  218.             End With
  219.         Else
  220.             'Property page is about to be opened
  221.             'Make sure the form is loaded
  222.                 Diameter# = Graphic.Properties("Diameter")
  223.                 Length# = Graphic.Properties("Length")
  224.                 LengthThread = Graphic.Properties("LengthThread")
  225.                 TypeB = Graphic.Properties("BType")
  226.                 SSolid = Graphic.Properties("BoltSolid")
  227.             Load frmBolt3D
  228.             With frmBolt3D
  229.             
  230.                 'If more than one RRect is selected and they do not
  231.                 'have the same properties, don't set up this field
  232.                 On Error GoTo NoRType
  233.  
  234.                 'When the property page is opening, transfer the numeric
  235.                 'roundness value from the Graphic to the TextBox
  236.                 'Get the roundness property value from the Graphic
  237.                 'Set the TextBox control's text
  238.                 .txtdd.Text = Diameter#
  239.                 .txtLen = Length#
  240.                 .txtThread.Text = LengthThread#
  241.                  If SSolid = 1 Then
  242.                     .Surf_Solid1.Value = True
  243.                     .Surf_Solid.Value = False
  244.                  ElseIf SSolid = 0 Then
  245.                     .Surf_Solid1.Value = False
  246.                     .Surf_Solid.Value = True
  247.                  End If
  248.  
  249. NoRType:
  250.             End With
  251.         End If
  252.  
  253.         PageControls = True
  254.         Exit Function
  255.  
  256. Failed:
  257.         'For debugging purposes, report that an error occurred
  258.         If Err.Number <> 0 Then
  259.             MsgBox "Error in PageControls: " & Err.Description
  260.         End If
  261.  
  262.         'Return false if an error occurred
  263.         PageControls = False
  264. End Function
  265.  
  266. Public Function PageDone(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant)
  267.         'Done with form
  268.         Unload frmBolt3D
  269. End Function
  270.  
  271. Public Function PropertyPages(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant) As Boolean
  272.     With frmBolt3D
  273.         .Show vbModal
  274.         PropertyPages = Not .DialogCanceled
  275.     End With
  276. End Function
  277.  
  278. Public Function Wizard(ByVal ThisRegenMethod As Object, Optional WizardNumber As Variant) As Boolean
  279.     Wizard = False
  280. End Function
  281.  
  282. 'Called when vertex has been moved, or other geometry change
  283. Public Function OnGeometryChanged(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant)
  284.     'Do nothing
  285. End Function
  286.  
  287. 'Called when vertex is moved, or other geometry change
  288. Public Function OnGeometryChanging(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant) As Boolean
  289.     'OK to continue with change
  290.     OnGeometryChanging = True
  291. End Function
  292.  
  293. Public Function OnNewGraphic(ByVal grfThis1 As Object, ByVal boolCopy As Boolean) As Boolean
  294.     If boolCopy Then
  295.         'Vertices are already added for us...
  296.         OnNewGraphic = True
  297.         Exit Function
  298.     End If
  299. Dim grfThis As Graphic
  300.     Set grfThis = grfThis1
  301.     If grfThis.Application.ActiveDrawing.Properties("TileMode") <> imsiModelSpace Then
  302.         GoTo Failed
  303.     End If
  304.     On Error GoTo Failed
  305.     'New Graphic being created
  306.     'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
  307.     'First Vertex is "first point of axis"
  308.     grfThis.Vertices.UseWorldCS = True
  309.     grfThis.Vertices.Add 2#, 5#, 0#, False, , , False
  310.     
  311.     'Second Vertex is "Second point of axis"
  312.     grfThis.Vertices.Add 6#, 5#, 0#, False, , , False
  313.     
  314.     OnNewGraphic = True
  315.     Exit Function
  316.  
  317. Failed:
  318.     'Return false on failure
  319.     OnNewGraphic = False
  320. End Function
  321.  
  322. 'Function called whenever a copy of a graphic is being made
  323. Public Function OnCopyGraphic(ByVal grfCopy As Object, ByVal grfSource As Object) As Boolean
  324.     'Return false on failure
  325.     OnCopyGraphic = True
  326. End Function
  327.  
  328. 'Notification function called after graphic property is saved
  329. Public Function OnPropertyChanged(ByVal Graphic As Object, ByVal PropID As Long, _
  330.         ValueOld As Variant, ValueNew As Variant)
  331.     'Do nothing
  332. End Function
  333.  
  334. 'Notification function called when graphic property is saved
  335. Public Function OnPropertyChanging(ByVal Graphic As Object, ByVal PropID As Long, _
  336.         ValueOld As Variant, ValueNew As Variant) As Boolean
  337.     'OK to proceed
  338.     OnPropertyChanging = True
  339. End Function
  340.  
  341. 'Notification function called when graphic property is retrieved
  342. Public Function OnPropertyGet(ByVal Graphic As Object, ByVal PropID As Long)
  343.     'Do nothing
  344. End Function
  345.  
  346. 'Called when we need to update our object
  347. Public Function Regen(ByVal grfThis1 As Object)
  348.         'Setup error handler
  349.         On Error GoTo Failed
  350. Dim grfThis As Graphic
  351.         Set grfThis = grfThis1
  352.         'Set up lock (prevent recursion)
  353. Dim LockCount&
  354.         LockCount& = grfThis.RegenLock
  355.         'Setup error handler (make sure lock is removed)
  356.         On Error GoTo FailedLock
  357.         If LockCount& = 0 Then
  358.             'Delete any previous cosmetic children
  359. Dim dd#
  360.             dd = grfThis.Properties("Diameter")
  361. Dim TypeBb
  362.             TypeBb = grfThis.Properties("BType")
  363.                 
  364. '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  365. Dim Salp#, Calp#, L#
  366. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#
  367. Dim LenProp#
  368.             LenProp = grfThis.Properties("Length")
  369. Dim lThread#
  370.             lThread = grfThis.Properties("LengthThread")
  371.             If lThread > LenProp Then
  372.                 lThread = LenProp
  373.                 grfThis.Properties("LengthThread") = lThread
  374.             End If
  375.             grfThis.Vertices.UseWorldCS = True
  376.             With grfThis.Vertices
  377.                 X00 = .Item(0).X
  378.                 Y00 = .Item(0).Y
  379.                 Z00 = .Item(0).Z
  380.                 X01 = .Item(1).X
  381.                 Y01 = .Item(1).Y
  382.                 Z01 = .Item(1).Z
  383.                 L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00))
  384.                 Salp = (Y01 - Y00) / L
  385.                 Calp = (X01 - X00) / L
  386.             End With
  387. Dim ddOld#
  388.             ddOld = grfThis.Properties("DiameterOld")
  389. Dim LOld#
  390.             LOld = grfThis.Properties("LengthOld")
  391. Dim LThreadOld#
  392.             LThreadOld = grfThis.Properties("LengthThreadOld")
  393. Dim TypeBOld$
  394.             TypeBOld = grfThis.Properties("BTypeOld")
  395. Dim SSolid%, SolidOld%
  396.             SSolid = grfThis.Properties("BoltSolid")
  397.             SolidOld = grfThis.Properties("BoltSolidOld")
  398.         
  399. Dim CountCosm As Long, iCosm As Long
  400.             CountCosm = grfThis.Graphics.Count
  401.             If CountCosm > 1 Then
  402.                 For iCosm = 1 To CountCosm - 1
  403.                     grfThis.Graphics(iCosm).Properties("PenColor") = grfThis.Properties("PenColor")
  404.                 Next iCosm
  405.             End If
  406.             If grfThis.Properties("Selected") = False Or SSolid <> SolidOld Or Abs(L - LenProp) > Eps Or Abs(L - LOld) > Eps Or Abs(dd - ddOld) > Eps Or Abs(lThread - LThreadOld) > Eps Or TypeBb <> TypeBOld Then
  407.                 L = LenProp
  408.                 grfThis.Graphics.Clear gfCosmetic
  409. ' Block for Scaling
  410. Dim AddScale#
  411.                 AddScale = 1
  412.                 dd = dd * AddScale
  413.                 L = L * AddScale
  414.                 lThread = lThread * AddScale
  415.                 
  416.                 If TypeBb = "HexBolt" Then Call HexBolt(grfThis, dd, L, Salp, Calp, lThread, SSolid)
  417.                 If TypeBb = "SlottedBolt" Then Call SlottedBolt(grfThis, dd, L, Salp, Calp, lThread, SSolid)
  418.                 If TypeBb = "HexFlScrew" Then Call HexFlScrew(grfThis, dd, L, Salp, Calp, lThread, SSolid)
  419. ' Block for Unscaling
  420.                 dd = dd / AddScale
  421.                 L = L / AddScale
  422.                 lThread = lThread / AddScale
  423.                 
  424.                 grfThis.Properties("DiameterOld") = dd
  425.                 grfThis.Properties("LengthOld") = L
  426.                 grfThis.Properties("LengthThreadOld") = lThread
  427.                 grfThis.Properties("DiameterOld") = dd
  428.                 grfThis.Properties("BTypeOld") = TypeBb
  429.                 grfThis.Properties("BoltSolidOld") = SSolid
  430.             End If
  431.             
  432.         End If
  433.  
  434.         
  435.         grfThis.RegenUnlock
  436.         Exit Function
  437.  
  438. FailedLock:
  439.         'Remove lock
  440.         grfThis.RegenUnlock
  441.  
  442. Failed:
  443. End Function
  444.  
  445. Public Function Draw(ByVal grfThis As Object, ByVal view As Object, Optional mat As Variant) As Boolean
  446.     'Return True if we did the redraw (no further processing necessary, no children will be drawn).
  447.     'Since this is just a test, we return False to let TurboCAD do the drawing operation.
  448.     Draw = False
  449. End Function
  450. Private Function Angle(sinb As Double, cosb As Double) As Double
  451.  
  452.         If Abs(cosb) < 0.0001 Then
  453.             If sinb > 0 Then
  454.                 Angle = Pi / 2
  455.             Else
  456.                 Angle = 3 * Pi / 2
  457.             End If
  458.         Else
  459.             If sinb >= 0 And cosb > 0 Then Angle = Atn(sinb / cosb)
  460.             If sinb >= 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
  461.             If sinb < 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
  462.             If sinb < 0 And cosb > 0 Then Angle = 2 * Pi + Atn(sinb / cosb)
  463.         End If
  464. End Function
  465.  
  466. ' HexBolt
  467.  
  468. Private Sub HexBolt(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, lThread As Double, SSolid As Integer)
  469. On Error GoTo Failed
  470. Dim D#, H#, T#, J#, del#, E#, F#
  471.         D = 1.75 * dd
  472.         H = 0.65 * dd
  473.         E = 0.875 * H
  474.         F = D / 4#
  475.         del = 0.1 * dd
  476.  
  477. Dim Grs As Graphics
  478.     Set Grs = Gr.Application.ActiveDrawing.Graphics
  479. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#
  480. Dim AddScale#, L1#
  481.         AddScale = 1
  482.         Gr.Vertices.UseWorldCS = True
  483.         With Gr.Vertices
  484.             X00 = .Item(0).X
  485.             Y00 = .Item(0).Y
  486.             Z00 = .Item(0).Z
  487.             X01 = .Item(1).X
  488.             Y01 = .Item(1).Y
  489.             Z01 = .Item(1).Z
  490.             L1 = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00))
  491.             If Abs(L + H - L1) > 0.001 Then
  492.                 .Item(0).X = X00 - (X01 - X00) * H / AddScale / L1
  493.                 .Item(0).Y = Y00 - (Y01 - Y00) * H / AddScale / L1
  494.                 .Item(0).Z = Z00 - (Z01 - Z00) * H / AddScale / L1
  495.                 .Item(1).X = X00 + (X01 - X00) * L / AddScale / L1
  496.                 .Item(1).Y = Y00 + (Y01 - Y00) * L / AddScale / L1
  497.                 .Item(1).Z = Z00 + (Z01 - Z00) * L / AddScale / L1
  498.                 X01 = X00 + (X01 - X00) * L / L1
  499.                 Y01 = Y00 + (Y01 - Y00) * L / L1
  500.                 Z01 = Z00 + (Z01 - Z00) * L / L1
  501.             End If
  502.         End With
  503.  
  504. Dim X00New#, Y00New#, Z00New#, X01New#, Y01New#, Z01New#
  505.         X00New = X00
  506.         Y00New = Y00
  507.         Z00New = Z00
  508.         X01New = X01
  509.         Y01New = Y01
  510.         Z01New = Z01
  511.         X00 = 0
  512.         Y00 = 0
  513.         Z00 = 0
  514.         X01 = L
  515.         Y01 = 0
  516.         Z01 = 0
  517.         
  518. Dim X0(100)
  519. Dim Y0(100)
  520. '################################################################
  521. 'Cylinder
  522.        X0(1) = -0.5 * H
  523.        Y0(1) = 0#
  524.        
  525.        X0(2) = -0.5 * H
  526.        Y0(2) = dd / 2
  527.        
  528.        X0(3) = L - del
  529.        Y0(3) = dd / 2#
  530.        
  531.        X0(4) = 1 * L
  532.        Y0(4) = dd / 2 - del
  533.        
  534.        X0(5) = 1 * L
  535.        Y0(5) = 0#
  536.        
  537.        X0(6) = X0(1)
  538.        Y0(6) = Y0(1)
  539.  
  540. Dim i%
  541. Dim Gr1 As Graphic
  542. Dim GrTemp As Graphic
  543. 'Add child Graphics revolve Contour
  544.             Set GrTemp = Grs.Add(gkGraphic)
  545.             With GrTemp.Vertices
  546.                 For i = 1 To 6
  547.                     .Add X0(i), Y0(i), 0
  548.                 Next i
  549.             End With
  550.             GrTemp.Closed = True
  551.             Set Gr1 = Grs.Add(, "TCW40SPIN")
  552.             Gr1.Properties("Solid") = SSolid
  553.             Gr1.Properties("$ROTATIONANGLE") = 2 * Pi
  554.             Gr1.Properties("$ROTATIONCOPY") = 30
  555.             Set GrTemp = Grs.Remove(GrTemp.Index)
  556.             Gr1.Graphics.AddGraphic GrTemp
  557.             Gr1.Vertices.Add X0(1), Y0(1), 0, False, False, False, False, False
  558.             Gr1.Vertices.Add X0(5), Y0(5), 0, False, False, False, False, False
  559. '################################################################
  560. ' Thread
  561.     'Base contour
  562. Dim hThread# ' Step of the thread
  563.     hThread = del / Sin(Pi / 3)
  564. Dim nCoil As Long, k As Long
  565.     nCoil = 10
  566.     nCoil = CLng(lThread / hThread)
  567.     
  568. Dim lThreadNew#
  569.     lThreadNew = nCoil * hThread
  570. Dim k1 As Long
  571.     X0(1) = L#
  572.     Y0(1) = dd#
  573.     
  574.     X0(2) = L#
  575.     Y0(2) = dd / 2
  576.     k1 = 2
  577.     For i = 1 To nCoil
  578.         k1 = k1 + 1
  579.         X0(k1) = X0(k1 - 1) - hThread / 2
  580.         Y0(k1) = Y0(k1 - 1) - del
  581.         k1 = k1 + 1
  582.         X0(k1) = X0(k1 - 1) - hThread / 2
  583.         Y0(k1) = Y0(k1 - 1) + del
  584.     Next i
  585.     
  586.     k1 = k1 + 1
  587.     X0(k1) = L - lThreadNew
  588.     Y0(k1) = dd
  589.     
  590.     k1 = k1 + 1
  591.     X0(k1) = L
  592.     Y0(k1) = dd
  593. Set GrTemp = Grs.Add(gkGraphic)
  594. With GrTemp.Vertices
  595.     For i = 1 To k1
  596.         .Add X0(i), Y0(i), 0
  597.     Next i
  598. End With
  599. GrTemp.Closed = True
  600. Dim Gr2 As Graphic
  601. Set Gr2 = Grs.Add(, "TCW40SPIN")
  602. Gr2.Properties("Solid") = SSolid
  603. Gr2.Properties("$ROTATIONANGLE") = 2 * Pi
  604. Gr2.Properties("$ROTATIONCOPY") = 30
  605. Set GrTemp = Grs.Remove(GrTemp.Index)
  606. Gr2.Graphics.AddGraphic GrTemp
  607. Gr2.Vertices.Add X01, Y01, 0, False, False, False, False, False
  608. Gr2.Vertices.Add X00, Y00, 0, False, False, False, False, False
  609. '###############################################################
  610. ' Head of the bolt
  611.     For i = 7 To 13
  612.         X0(i) = D / 2 * Cos(Pi / 3 * (i - 7))
  613.         Y0(i) = D / 2 * Sin(Pi / 3 * (i - 7))
  614.     Next i
  615. Dim Gr3 As Graphic
  616. Set Gr3 = Grs.Add(gkGraphic)
  617. With Gr3.Vertices
  618.     For i = 7 To 13
  619.         .Add X0(i), Y0(i), 0, True, True, False, False, False, False
  620.     Next i
  621. End With
  622. Gr3.Closed = True
  623. Gr3.Properties("Thickness") = H
  624. Gr3.Properties("Solid") = SSolid
  625. Dim xTo#, yTo#, zTo#, xFrom#, yFrom#, zFrom#, xRef#, yRef#, zRef#
  626.     xTo = X00 + (X01 - X00) / L
  627.     yTo = Y00 + (Y01 - Y00) / L
  628.     zTo = 0
  629.     xFrom = X00
  630.     yFrom = Y00
  631.     zFrom = 1#
  632.     xRef = X00
  633.     yRef = Y00
  634.     zRef = 0#
  635.     Gr3.RotateAbsolute xTo, yTo, zTo, xFrom, yFrom, zFrom, xRef, yRef, zRef
  636. '##################################################################
  637.  'faska on head
  638.     T = D / 2 * Sin(Pi / 3)
  639.        X0(1) = -1.1 * H
  640.        Y0(1) = T * 0.7 - 0.1 * H / Tan(Pi / 6)
  641.        
  642.        X0(2) = -1.1 * H
  643.        Y0(2) = D
  644.        
  645.        X0(3) = -H + 0.4 * H
  646.        Y0(3) = D
  647.        
  648.        X0(4) = -H + 0.4 * H
  649.        Y0(4) = T * 0.7 + 0.5 * H / Tan(Pi / 6)
  650.        
  651.        X0(5) = X0(1)
  652.        Y0(5) = Y0(1)
  653.        
  654. '-----------------------------------------------------------
  655.        
  656.             Set GrTemp = Grs.Add(gkGraphic)
  657.             With GrTemp.Vertices
  658.                 For i = 1 To 5
  659.                     .Add X0(i), Y0(i), 0
  660.                 Next i
  661.             End With
  662.             GrTemp.Closed = True
  663. Dim Gr4 As Graphic
  664.             Set Gr4 = Grs.Add(, "TCW40SPIN")
  665.             Gr4.Properties("Solid") = SSolid
  666.             Gr4.Properties("$ROTATIONANGLE") = 2 * Pi
  667.             Gr4.Properties("$ROTATIONCOPY") = 30
  668.             Set GrTemp = Grs.Remove(GrTemp.Index)
  669.             Gr4.Graphics.AddGraphic GrTemp
  670.             Gr4.Vertices.Add X00, Y00, 0, False, False, False, False, False
  671.             Gr4.Vertices.Add X01, Y01, 0, False, False, False, False, False
  672. '#################################################################
  673. ' Boolean operations
  674. Dim Bool3D As Boolean3D
  675.     Set Bool3D = New Boolean3D
  676. Dim Res As Long
  677. Dim GrIndex As Long
  678.     
  679. Dim GrRes1 As Graphic
  680.     Gr1.Update
  681.     Gr2.Update
  682.     Set GrRes1 = Bool3D.Subtract(Gr1, Gr2)
  683.  
  684.     If (Not GrRes1 Is Nothing) Then
  685.         Gr1.Deleted = True
  686.         Gr2.Deleted = True
  687.         Grs.AddGraphic GrRes1
  688.     End If
  689.  Dim GrRes2 As Graphic
  690.  
  691.     GrRes1.Update
  692.     Gr3.Update
  693.     Set GrRes2 = Bool3D.Add(GrRes1, Gr3)
  694.     If (Not GrRes2 Is Nothing) Then
  695.         GrRes1.Deleted = True
  696.         Gr3.Deleted = True
  697.         Grs.AddGraphic GrRes2
  698.     End If
  699.    
  700.  Dim GrRes3 As Graphic
  701.     GrRes2.Update
  702.     Gr4.Update
  703.     Set GrRes3 = Bool3D.Subtract(GrRes2, Gr4)
  704.     If (Not GrRes3 Is Nothing) Then
  705.         GrRes2.Deleted = True
  706.         Gr4.Deleted = True
  707.         Grs.AddGraphic GrRes3
  708.     End If
  709.     
  710.     GrIndex = GrRes3.Index
  711.     Grs.Remove GrIndex
  712.     Gr.Graphics.AddGraphic GrRes3
  713.     GrRes3.Cosmetic = True
  714.     GrRes3.Properties("PenColor") = Gr.Properties("PenColor")
  715. '?????????????????????????????????????????????????????????????
  716. Dim GrLine As Graphic
  717.     Set GrLine = Grs.Add(11)
  718.     GrLine.Vertices.UseWorldCS = True
  719.     With GrLine.Vertices
  720.         .Add -H, 0, 0
  721.         .Add L, 0, 0
  722.     End With
  723.     GrLine.Properties("PenColor") = RGB(255, 0, 0)
  724.     GrIndex = GrLine.Index
  725.     Grs.Remove GrIndex
  726.     Gr.Graphics.AddGraphic GrLine
  727.     GrLine.Cosmetic = True
  728. Dim xx0#, yy0#, zz0#, xx1#, yy1#, zz1#
  729.  
  730.     GrLine.Vertices.UseWorldCS = False
  731.     With GrLine.Vertices
  732.         xx0 = .Item(0).X
  733.         yy0 = .Item(0).Y
  734.         zz0 = .Item(0).Z
  735.         xx1 = .Item(1).X
  736.         yy1 = .Item(1).Y
  737.         zz1 = .Item(1).Z
  738.     End With
  739.     Gr.Vertices.UseWorldCS = False
  740.     With Gr.Vertices
  741.         X00New = .Item(0).X
  742.         Y00New = .Item(0).Y
  743.         Z00New = .Item(0).Z
  744.    End With
  745.     GrRes3.MoveRelative X00New - xx0, Y00New - yy0, Z00New - zz0
  746.     GrLine.Deleted = True
  747. '?????????????????????????????????????????????????????????????
  748.  
  749.     Set Gr1 = Nothing
  750.     Set Gr2 = Nothing
  751.     Set Gr3 = Nothing
  752.     Set Gr4 = Nothing
  753.     Set GrRes1 = Nothing
  754.     Set GrRes2 = Nothing
  755.     Set GrRes3 = Nothing
  756.     Set GrTemp = Nothing
  757.     Set Grs = Nothing
  758.     Set Bool3D = Nothing
  759.     
  760. Exit Sub
  761. Failed:
  762.  
  763.         If Err.Number <> 0 Then
  764.             MsgBox "Regen error: " & Err.Description
  765.         End If
  766. End Sub
  767.  
  768.  
  769. ' Slotted Bolt
  770.  
  771. Private Sub SlottedBolt(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, lThread As Double, SSolid As Integer)
  772. On Error GoTo Failed
  773. Dim D#, H#, T#, J#, del#, E#, F#
  774.         D = 1.875 * dd
  775.         H = 0.494 * dd
  776.         T = 0.24 * dd
  777.         J = 0.19 * dd
  778.         del = 0.1 * dd
  779.  
  780. Dim Grs As Graphics
  781.     Set Grs = Gr.Application.ActiveDrawing.Graphics
  782. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#
  783. Dim AddScale#, L1#
  784.         AddScale = 1
  785.         Gr.Vertices.UseWorldCS = True
  786.         With Gr.Vertices
  787.             X00 = .Item(0).X
  788.             Y00 = .Item(0).Y
  789.             Z00 = .Item(0).Z
  790.             X01 = .Item(1).X
  791.             Y01 = .Item(1).Y
  792.             Z01 = .Item(1).Z
  793.             L1 = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00))
  794.             .Item(1).X = X00 + (X01 - X00) * L / AddScale / L1
  795.             .Item(1).Y = Y00 + (Y01 - Y00) * L / AddScale / L1
  796.             .Item(1).Z = Z00 + (Z01 - Z00) * L / AddScale / L1
  797.             X01 = X00 + (X01 - X00) * L / L1
  798.             Y01 = Y00 + (Y01 - Y00) * L / L1
  799.             Z01 = Z00 + (Z01 - Z00) * L / L1
  800.         End With
  801. Dim X00New#, Y00New#, Z00New#, X01New#, Y01New#, Z01New#
  802.         X00New = X00
  803.         Y00New = Y00
  804.         Z00New = Z00
  805.         X01New = X01
  806.         Y01New = Y01
  807.         Z01New = Z01
  808.         X00 = 0
  809.         Y00 = 0
  810.         Z00 = 0
  811.         X01 = L
  812.         Y01 = 0
  813.         Z01 = 0
  814.         
  815.  
  816. Dim X0(100)
  817. Dim Y0(100)
  818.        
  819.        X0(1) = 0.9 * H
  820.        Y0(1) = 0#
  821.        
  822.        X0(2) = 0.9 * H
  823.        Y0(2) = dd / 2
  824.        
  825.        X0(3) = L - del
  826.        Y0(3) = dd / 2#
  827.        
  828.        X0(4) = 1 * L
  829.        Y0(4) = dd / 2 - del
  830.        
  831.        X0(5) = 1 * L
  832.        Y0(5) = 0#
  833.        
  834.        X0(6) = X0(1)
  835.        Y0(6) = Y0(1)
  836. '-----------------------------------------------------------
  837.        
  838. Dim i%
  839.        
  840. Dim Gr1 As Graphic
  841. Dim GrTemp As Graphic
  842. 'Add child Graphics revolve Contour
  843.             Set GrTemp = Grs.Add(gkGraphic)
  844.             With GrTemp.Vertices
  845.                 For i = 1 To 6
  846.                     .Add X0(i), Y0(i), 0
  847.                 Next i
  848.             End With
  849.             GrTemp.Closed = True
  850.             Set Gr1 = Grs.Add(, "TCW40SPIN")
  851.             Gr1.Properties("Solid") = SSolid
  852.             Gr1.Properties("$ROTATIONANGLE") = 2 * Pi
  853.             Gr1.Properties("$ROTATIONCOPY") = 30
  854.             Set GrTemp = Grs.Remove(GrTemp.Index)
  855.             Gr1.Graphics.AddGraphic GrTemp
  856.             Gr1.Vertices.Add X0(1), Y0(1), 0, False, False, False, False, False
  857.             Gr1.Vertices.Add X0(5), Y0(5), 0, False, False, False, False, False
  858.             
  859. ' Thread
  860.     'Base contour
  861. Dim hThread# ' Step of the thread
  862.     hThread = del / Sin(Pi / 3)
  863. Dim nCoil As Long, k As Long
  864.     nCoil = 10
  865.     nCoil = CLng(lThread / hThread)
  866.     
  867. Dim lThreadNew#
  868.     lThreadNew = nCoil * hThread
  869. Dim k1 As Long
  870.     
  871.     X0(1) = L#
  872.     Y0(1) = dd#
  873.     
  874.     X0(2) = L#
  875.     Y0(2) = dd / 2
  876.     
  877.     k1 = 2
  878.     
  879.     For i = 1 To nCoil
  880.         k1 = k1 + 1
  881.         X0(k1) = X0(k1 - 1) - hThread / 2
  882.         Y0(k1) = Y0(k1 - 1) - del
  883.         k1 = k1 + 1
  884.         X0(k1) = X0(k1 - 1) - hThread / 2
  885.         Y0(k1) = Y0(k1 - 1) + del
  886.     Next i
  887.     k1 = k1 + 1
  888.     X0(k1) = L - lThreadNew
  889.     Y0(k1) = dd
  890.     
  891.     k1 = k1 + 1
  892.     X0(k1) = L
  893.     Y0(k1) = dd
  894.  
  895.     Set GrTemp = Grs.Add(gkGraphic)
  896.     With GrTemp.Vertices
  897.         For i = 1 To k1
  898.             .Add X0(i), Y0(i), 0
  899.         Next i
  900.     End With
  901.     GrTemp.Closed = True
  902.  
  903. Dim Gr2 As Graphic
  904.     Set Gr2 = Grs.Add(, "TCW40SPIN")
  905.     Gr2.Properties("Solid") = SSolid
  906.     Gr2.Properties("$ROTATIONANGLE") = 2 * Pi
  907.     Gr2.Properties("$ROTATIONCOPY") = 30
  908.     Set GrTemp = Grs.Remove(GrTemp.Index)
  909.     Gr2.Graphics.AddGraphic GrTemp
  910.     Gr2.Vertices.Add X01, Y01, 0, False, False, False, False, False
  911.     Gr2.Vertices.Add X00, Y00, 0, False, False, False, False, False
  912.  
  913. '############################################################
  914. '############################################################
  915. ' Head of the bolt
  916.  
  917.        X0(1) = 0#
  918.        Y0(1) = 0#
  919.        
  920.        X0(2) = 0#
  921.        Y0(2) = D / 2#
  922.        
  923.        X0(3) = H
  924.        Y0(3) = dd / 2#
  925.        
  926.        X0(4) = H
  927.        Y0(4) = 0#
  928.        
  929.        X0(5) = X0(1)
  930.        Y0(5) = Y0(1)
  931.        
  932.         Set GrTemp = Grs.Add(gkGraphic)
  933.             
  934.         With GrTemp.Vertices
  935.             For i = 1 To 5
  936.                 .Add X0(i), Y0(i), 0
  937.             Next i
  938.         End With
  939.         GrTemp.Closed = True
  940. Dim Gr3 As Graphic
  941.         Set Gr3 = Grs.Add(, "TCW40SPIN")
  942.         Gr3.Properties("Solid") = SSolid
  943.         Gr3.Properties("$ROTATIONANGLE") = 2 * Pi
  944.         Gr3.Properties("$ROTATIONCOPY") = 30
  945.         Set GrTemp = Grs.Remove(GrTemp.Index)
  946.         Gr3.Graphics.AddGraphic GrTemp
  947.         Gr3.Vertices.Add X0(1), Y0(1), 0, False, False, False, False, False
  948.         Gr3.Vertices.Add X0(4), Y0(4), 0, False, False, False, False, False
  949.        
  950. '################################################################
  951. '################################################################
  952.  
  953.        X0(1) = -0.1 * H
  954.        Y0(1) = 1.1 * D / 2
  955.        
  956.        X0(2) = T
  957.        Y0(2) = 1.1 * D / 2
  958.        
  959.        X0(3) = T
  960.        Y0(3) = -1.1 * D / 2
  961.        
  962.        X0(4) = -0.1 * H
  963.        Y0(4) = -1.1 * D / 2
  964.        
  965.        X0(5) = X0(1)
  966.        Y0(5) = Y0(1)
  967.        
  968. '-----------------------------------------------------------
  969. Dim Gr4 As Graphic
  970.             Set Gr4 = Grs.Add(gkGraphic)
  971.             With Gr4.Vertices
  972.                 For i = 1 To 5
  973.                     .Add X0(i), Y0(i), 0
  974.                 Next i
  975.             End With
  976.             Gr4.Closed = True
  977.             Gr4.Properties("Thickness") = J
  978.             Gr4.Properties("Solid") = SSolid
  979.             Gr4.MoveRelative 0#, 0#, -J / 2
  980. '#################################################################
  981. '################################################################
  982. ' Boolean operations
  983. Dim Bool3D As Boolean3D
  984.     Set Bool3D = New Boolean3D
  985. Dim Res As Long
  986. Dim GrIndex As Long
  987.     
  988. Dim GrRes1 As Graphic
  989.     Gr1.Update
  990.     Gr2.Update
  991.     Set GrRes1 = Bool3D.Subtract(Gr1, Gr2)
  992.     If (Not GrRes1 Is Nothing) Then
  993.         Gr1.Deleted = True
  994.         Gr2.Deleted = True
  995.         Grs.AddGraphic GrRes1
  996.     End If
  997.     
  998.  Dim GrRes2 As Graphic
  999.     GrRes1.Update
  1000.     Gr3.Update
  1001.     Set GrRes2 = Bool3D.Add(GrRes1, Gr3)
  1002.     If (Not GrRes2 Is Nothing) Then
  1003.         GrRes1.Deleted = True
  1004.         Gr3.Deleted = True
  1005.         Grs.AddGraphic GrRes2
  1006.     End If
  1007.    
  1008.  Dim GrRes3 As Graphic
  1009.     GrRes2.Update
  1010.     Gr4.Update
  1011.     Set GrRes3 = Bool3D.Subtract(GrRes2, Gr4)
  1012.     If (Not GrRes3 Is Nothing) Then
  1013.         GrRes2.Deleted = True
  1014.         Gr4.Deleted = True
  1015.         Grs.AddGraphic GrRes3
  1016.     End If
  1017.     
  1018.     GrIndex = GrRes3.Index
  1019.     Grs.Remove GrIndex
  1020.     Gr.Graphics.AddGraphic GrRes3
  1021.     GrRes3.Cosmetic = True
  1022.     GrRes3.Properties("PenColor") = Gr.Properties("PenColor")
  1023. '?????????????????????????????????????????????????????????????
  1024. Dim GrLine As Graphic
  1025.     Set GrLine = Grs.Add(11)
  1026.     GrLine.Vertices.UseWorldCS = True
  1027.     With GrLine.Vertices
  1028.         .Add 0, 0, 0
  1029.         .Add L, 0, 0
  1030.     End With
  1031.     GrLine.Properties("PenColor") = RGB(255, 0, 0)
  1032.     GrIndex = GrLine.Index
  1033.     Grs.Remove GrIndex
  1034.     Gr.Graphics.AddGraphic GrLine
  1035.     GrLine.Cosmetic = True
  1036. Dim xx0#, yy0#, zz0#, xx1#, yy1#, zz1#
  1037.     GrLine.Vertices.UseWorldCS = False
  1038.     With GrLine.Vertices
  1039.         xx0 = .Item(0).X
  1040.         yy0 = .Item(0).Y
  1041.         zz0 = .Item(0).Z
  1042.         xx1 = .Item(1).X
  1043.         yy1 = .Item(1).Y
  1044.         zz1 = .Item(1).Z
  1045.     End With
  1046.     Gr.Vertices.UseWorldCS = False
  1047.     With Gr.Vertices
  1048.         X00New = .Item(0).X
  1049.         Y00New = .Item(0).Y
  1050.         Z00New = .Item(0).Z
  1051.     End With
  1052.     GrRes3.MoveRelative X00New - xx0, Y00New - yy0, Z00New - zz0
  1053.     GrLine.Deleted = True
  1054. '?????????????????????????????????????????????????????????????
  1055.  
  1056.     Set Gr1 = Nothing
  1057.     Set Gr2 = Nothing
  1058.     Set Gr3 = Nothing
  1059.     Set Gr4 = Nothing
  1060.     Set GrRes1 = Nothing
  1061.     Set GrRes2 = Nothing
  1062.     Set GrRes3 = Nothing
  1063.     Set GrTemp = Nothing
  1064.     Set Grs = Nothing
  1065.     Set Bool3D = Nothing
  1066.     
  1067. Exit Sub
  1068. Failed:
  1069.  
  1070.         If Err.Number <> 0 Then
  1071.             MsgBox "Regen error: " & Err.Description
  1072.         End If
  1073. End Sub
  1074.  
  1075.  
  1076.  
  1077.  
  1078. ' HexFlange Screw
  1079.  
  1080. Private Sub HexFlScrew(Gr As Graphic, dd As Double, L As Double, Salp As Double, Calp As Double, lThread As Double, SSolid As Integer)
  1081. On Error GoTo Failed
  1082. Dim D#, Dw#, Di#, C#, k1#, k#, E#, del#
  1083.         D = 1.4 * dd
  1084.         Dw = 2.08 * dd
  1085.         C = 0.15 * dd
  1086.         k1 = 0.43 * dd
  1087.         k = 0.97 * dd
  1088.         E = (k - k1) * 0.85
  1089.         Di = D * Sin(Pi / 3)
  1090.         del = 0.1 * dd
  1091.  
  1092. Dim Grs As Graphics
  1093.     Set Grs = Gr.Application.ActiveDrawing.Graphics
  1094. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#
  1095. Dim AddScale#, L1#
  1096.         AddScale = 1
  1097.         Gr.Vertices.UseWorldCS = True
  1098.         With Gr.Vertices
  1099.             X00 = .Item(0).X
  1100.             Y00 = .Item(0).Y
  1101.             Z00 = .Item(0).Z
  1102.             X01 = .Item(1).X
  1103.             Y01 = .Item(1).Y
  1104.             Z01 = .Item(1).Z
  1105.             L1 = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00))
  1106.             If Abs(L + k - L1) > 0.001 Then
  1107.                 .Item(0).X = X00 - (X01 - X00) * k / AddScale / L1
  1108.                 .Item(0).Y = Y00 - (Y01 - Y00) * k / AddScale / L1
  1109.                 .Item(0).Z = Z00 - (Z01 - Z00) * k / AddScale / L1
  1110.                 .Item(1).X = X00 + (X01 - X00) * L / AddScale / L1
  1111.                 .Item(1).Y = Y00 + (Y01 - Y00) * L / AddScale / L1
  1112.                 .Item(1).Z = Z00 + (Z01 - Z00) * L / AddScale / L1
  1113.                 X01 = X00 + (X01 - X00) * L / L1
  1114.                 Y01 = Y00 + (Y01 - Y00) * L / L1
  1115.                 Z01 = Z00 + (Z01 - Z00) * L / L1
  1116.             End If
  1117.         End With
  1118. Dim X00New#, Y00New#, Z00New#, X01New#, Y01New#, Z01New#
  1119.         X00New = X00
  1120.         Y00New = Y00
  1121.         Z00New = Z00
  1122.         X01New = X01
  1123.         Y01New = Y01
  1124.         Z01New = Z01
  1125.         X00 = 0
  1126.         Y00 = 0
  1127.         Z00 = 0
  1128.         X01 = L
  1129.         Y01 = 0
  1130.         Z01 = 0
  1131.         
  1132. Dim X0(100)
  1133. Dim Y0(100)
  1134.        X0(1) = -0.5 * k
  1135.        Y0(1) = 0#
  1136.        
  1137.        X0(2) = -0.5 * k
  1138.        Y0(2) = dd / 2
  1139.        
  1140.        X0(3) = L - del
  1141.        Y0(3) = dd / 2#
  1142.        
  1143.        X0(4) = 1 * L
  1144.        Y0(4) = dd / 2 - del
  1145.        
  1146.        X0(5) = 1 * L
  1147.        Y0(5) = 0#
  1148.        
  1149.        X0(6) = X0(1)
  1150.        Y0(6) = Y0(1)
  1151. '-----------------------------------------------------------
  1152. Dim i%
  1153.        
  1154. Dim Gr1 As Graphic
  1155. Dim GrTemp As Graphic
  1156. 'Add child Graphics revolve Contour
  1157.             
  1158.             Set GrTemp = Grs.Add(gkGraphic)
  1159.             
  1160.             With GrTemp.Vertices
  1161.                 For i = 1 To 6
  1162.                     .Add X0(i), Y0(i), 0
  1163.                 Next i
  1164.             End With
  1165.             GrTemp.Closed = True
  1166.             Set Gr1 = Grs.Add(, "TCW40SPIN")
  1167.             Gr1.Properties("Solid") = SSolid
  1168.             Gr1.Properties("$ROTATIONANGLE") = 2 * Pi
  1169.             Gr1.Properties("$ROTATIONCOPY") = 30
  1170.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1171.             Gr1.Graphics.AddGraphic GrTemp
  1172.             Gr1.Vertices.Add X0(1), Y0(1), 0, False, False, False, False, False
  1173.             Gr1.Vertices.Add X0(5), Y0(5), 0, False, False, False, False, False
  1174.             
  1175. ' Thread
  1176.     'Base contour
  1177. Dim hThread# ' Step of the thread
  1178.     hThread = del / Sin(Pi / 3)
  1179. Dim nCoil As Long ', K As Long
  1180.     nCoil = 10
  1181.     nCoil = CLng(lThread / hThread)
  1182.     
  1183. Dim lThreadNew#
  1184.     lThreadNew = nCoil * hThread
  1185. Dim k2 As Long
  1186.     
  1187.     X0(1) = L#
  1188.     Y0(1) = dd#
  1189.     
  1190.     X0(2) = L#
  1191.     Y0(2) = dd / 2
  1192.     
  1193.     k2 = 2
  1194.     
  1195.     For i = 1 To nCoil
  1196.         k2 = k2 + 1
  1197.         X0(k2) = X0(k2 - 1) - hThread / 2
  1198.         Y0(k2) = Y0(k2 - 1) - del
  1199.         k2 = k2 + 1
  1200.         X0(k2) = X0(k2 - 1) - hThread / 2
  1201.         Y0(k2) = Y0(k2 - 1) + del
  1202.     Next i
  1203.     k2 = k2 + 1
  1204.     X0(k2) = L - lThreadNew
  1205.     Y0(k2) = dd
  1206.     
  1207.     k2 = k2 + 1
  1208.     X0(k2) = L
  1209.     Y0(k2) = dd
  1210.  
  1211.     Set GrTemp = Grs.Add(gkGraphic)
  1212.     With GrTemp.Vertices
  1213.         For i = 1 To k2
  1214.             .Add X0(i), Y0(i), 0
  1215.         Next i
  1216.     End With
  1217.     GrTemp.Closed = True
  1218.  
  1219. Dim Gr2 As Graphic
  1220.     Set Gr2 = Grs.Add(, "TCW40SPIN")
  1221.     Gr2.Properties("Solid") = SSolid
  1222.     Gr2.Properties("$ROTATIONANGLE") = 2 * Pi
  1223.     Gr2.Properties("$ROTATIONCOPY") = 30
  1224.     Set GrTemp = Grs.Remove(GrTemp.Index)
  1225.     Gr2.Graphics.AddGraphic GrTemp
  1226.     Gr2.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1227.     Gr2.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1228.  
  1229.  
  1230. ' Head of the bolt
  1231.     For i = 7 To 13
  1232.         X0(i) = D / 2 * Cos(Pi / 3 * (i - 7))
  1233.         Y0(i) = D / 2 * Sin(Pi / 3 * (i - 7))
  1234.     Next i
  1235. Dim Gr3 As Graphic
  1236.     Set Gr3 = Grs.Add(gkGraphic)
  1237.     With Gr3.Vertices
  1238.         For i = 7 To 13
  1239.             .Add X0(i), Y0(i), 0, True, True, False, False, False, False
  1240.         Next i
  1241.     End With
  1242.     Gr3.Closed = True
  1243.     Gr3.Properties("Thickness") = k
  1244.     Gr3.Properties("Solid") = SSolid
  1245. Dim xTo#, yTo#, zTo#, xFrom#, yFrom#, zFrom#, xRef#, yRef#, zRef#
  1246.     xTo = X00 + (X01 - X00) / L
  1247.     yTo = Y00 + (Y01 - Y00) / L
  1248.     zTo = 0
  1249.     xFrom = X00
  1250.     yFrom = Y00
  1251.     zFrom = 1#
  1252.     xRef = X00
  1253.     yRef = Y00
  1254.     zRef = 0#
  1255.     Gr3.RotateAbsolute xTo, yTo, zTo, xFrom, yFrom, zFrom, xRef, yRef, zRef
  1256. '################################################################
  1257. '################################################################
  1258. Dim T#
  1259.     T = D / 2 * Sin(Pi / 3)
  1260.        X0(1) = -1.1 * k
  1261.        Y0(1) = T * 0.7 - 0.1 * k / Tan(Pi / 6)
  1262.        
  1263.        X0(2) = -1.1 * k
  1264.        Y0(2) = D
  1265.        
  1266.        X0(3) = -k + 0.4 * k
  1267.        Y0(3) = D
  1268.        
  1269.        X0(4) = -k + 0.4 * k
  1270.        Y0(4) = T * 0.7 + 0.5 * k / Tan(Pi / 6)
  1271.        
  1272.        X0(5) = X0(1)
  1273.        Y0(5) = Y0(1)
  1274.        
  1275. '-----------------------------------------------------------
  1276.        
  1277.             Set GrTemp = Grs.Add(gkGraphic)
  1278.             With GrTemp.Vertices
  1279.                 For i = 1 To 5
  1280.                     .Add X0(i), Y0(i), 0
  1281.                 Next i
  1282.             End With
  1283.             GrTemp.Closed = True
  1284. Dim Gr4 As Graphic
  1285.             Set Gr4 = Grs.Add(, "TCW40SPIN")
  1286.             Gr4.Properties("Solid") = SSolid
  1287.             Gr4.Properties("$ROTATIONANGLE") = 2 * Pi
  1288.             Gr4.Properties("$ROTATIONCOPY") = 30
  1289.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1290.             Gr4.Graphics.AddGraphic GrTemp
  1291.             Gr4.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1292.             Gr4.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1293. '#################################################################
  1294.     
  1295. '  Begin Flange *******************************************
  1296.        X0(1) = -k1
  1297.        Y0(1) = 0#
  1298.        
  1299.        X0(2) = -k1
  1300.        Y0(2) = D / 2
  1301.        
  1302.        X0(3) = -C
  1303.        Y0(3) = Dw / 2
  1304.        
  1305.        X0(4) = 0.01 * k1#
  1306.        Y0(4) = Dw / 2
  1307.        
  1308.        X0(5) = 0.01 * k1
  1309.        Y0(5) = 0#
  1310.        
  1311.        X0(6) = X0(1)
  1312.        Y0(6) = Y0(1)
  1313.        
  1314. '-----------------------------------------------------------
  1315.             Set GrTemp = Grs.Add(gkGraphic)
  1316.             With GrTemp.Vertices
  1317.                 For i = 1 To 6
  1318.                     .Add X0(i), Y0(i), 0
  1319.                 Next i
  1320.             End With
  1321.             GrTemp.Closed = True
  1322. Dim Gr5 As Graphic
  1323.             Set Gr5 = Grs.Add(, "TCW40SPIN")
  1324.             Gr5.Properties("Solid") = SSolid
  1325.             Gr5.Properties("$ROTATIONANGLE") = 2 * Pi
  1326.             Gr5.Properties("$ROTATIONCOPY") = 30
  1327.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1328.             Gr5.Graphics.AddGraphic GrTemp
  1329.             Gr5.Vertices.Add X0(1), Y0(1), 0, False, False, False, False, False
  1330.             Gr5.Vertices.Add X0(5), Y0(5), 0, False, False, False, False, False
  1331. '  End Flange ***********************************************
  1332. ' Boolean operations
  1333. Dim Bool3D As Boolean3D
  1334.     Set Bool3D = New Boolean3D
  1335. Dim Res As Long
  1336. Dim GrIndex As Long
  1337.     
  1338. Dim GrRes1 As Graphic
  1339.     Gr1.Update
  1340.     Gr2.Update
  1341.     Set GrRes1 = Bool3D.Subtract(Gr1, Gr2)
  1342.     If (Not GrRes1 Is Nothing) Then
  1343.         Gr1.Deleted = True
  1344.         Gr2.Deleted = True
  1345.         Grs.AddGraphic GrRes1
  1346.     End If
  1347.     
  1348.  Dim GrRes2 As Graphic
  1349.     GrRes1.Update
  1350.     Gr3.Update
  1351.     Set GrRes2 = Bool3D.Add(GrRes1, Gr3)
  1352.     If (Not GrRes2 Is Nothing) Then
  1353.         GrRes1.Deleted = True
  1354.         Gr3.Deleted = True
  1355.         Grs.AddGraphic GrRes2
  1356.     End If
  1357.    
  1358.  Dim GrRes3 As Graphic
  1359.     GrRes2.Update
  1360.     Gr4.Update
  1361.     Set GrRes3 = Bool3D.Subtract(GrRes2, Gr4)
  1362.     If (Not GrRes3 Is Nothing) Then
  1363.         GrRes2.Deleted = True
  1364.         Gr4.Deleted = True
  1365.         Grs.AddGraphic GrRes3
  1366.     End If
  1367.     
  1368.  Dim GrRes4 As Graphic
  1369.     GrRes3.Update
  1370.     Gr5.Update
  1371.     Set GrRes4 = Bool3D.Add(GrRes3, Gr5)
  1372.     If (Not GrRes4 Is Nothing) Then
  1373.         GrRes3.Deleted = True
  1374.         Gr5.Deleted = True
  1375.         Grs.AddGraphic GrRes4
  1376.     End If
  1377.     
  1378.     GrIndex = GrRes4.Index
  1379.     Grs.Remove GrIndex
  1380.     Gr.Graphics.AddGraphic GrRes4
  1381.     GrRes4.Cosmetic = True
  1382.     GrRes4.Properties("PenColor") = Gr.Properties("PenColor")
  1383. '?????????????????????????????????????????????????????????????
  1384. Dim GrLine As Graphic
  1385.     Set GrLine = Grs.Add(11)
  1386.     GrLine.Vertices.UseWorldCS = True
  1387.     With GrLine.Vertices
  1388.         .Add -k, 0, 0
  1389.         .Add L, 0, 0
  1390.     End With
  1391.     GrLine.Properties("PenColor") = RGB(255, 0, 0)
  1392.     GrIndex = GrLine.Index
  1393.     Grs.Remove GrIndex
  1394.     Gr.Graphics.AddGraphic GrLine
  1395.     GrLine.Cosmetic = True
  1396. Dim xx0#, yy0#, zz0#, xx1#, yy1#, zz1#
  1397.  
  1398.     GrLine.Vertices.UseWorldCS = False
  1399.     With GrLine.Vertices
  1400.         xx0 = .Item(0).X
  1401.         yy0 = .Item(0).Y
  1402.         zz0 = .Item(0).Z
  1403.         xx1 = .Item(1).X
  1404.         yy1 = .Item(1).Y
  1405.         zz1 = .Item(1).Z
  1406.     End With
  1407.     Gr.Vertices.UseWorldCS = False
  1408.     With Gr.Vertices
  1409.         X00New = .Item(0).X
  1410.         Y00New = .Item(0).Y
  1411.         Z00New = .Item(0).Z
  1412.     End With
  1413.     GrRes4.MoveRelative X00New - xx0, Y00New - yy0, Z00New - zz0
  1414.     GrLine.Deleted = True
  1415. '?????????????????????????????????????????????????????????????
  1416.  
  1417.  
  1418.  
  1419.     Set Gr1 = Nothing
  1420.     Set Gr2 = Nothing
  1421.     Set Gr3 = Nothing
  1422.     Set Gr4 = Nothing
  1423.     Set Gr5 = Nothing
  1424.     Set GrRes1 = Nothing
  1425.     Set GrRes2 = Nothing
  1426.     Set GrRes3 = Nothing
  1427.     Set GrRes4 = Nothing
  1428.     Set GrTemp = Nothing
  1429.     Set Grs = Nothing
  1430.     Set Bool3D = Nothing
  1431.     
  1432. Exit Sub
  1433. Failed:
  1434.  
  1435.         If Err.Number <> 0 Then
  1436.             MsgBox "Regen error: " & Err.Description
  1437.         End If
  1438. End Sub
  1439.  
  1440.